home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / librw / RWXDRistream.z / RWXDRistream
Encoding:
Text File  |  1998-10-30  |  17.7 KB  |  463 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))                                          RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWXDRistream (Unix only) - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/xdrstrea.h>
  13.  
  14.  
  15.  
  16.  
  17.           XDR xdr;
  18.           xdrstdio_create(&xdr, stdin, XDR_DECODE);
  19.           RWXDRistream rw_xdr(&xdr);
  20.  
  21.  
  22.  
  23.  
  24. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  25.      Class RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm is a portable input stream based on XDR routines.
  26.      Class RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm encapsulates a portion of the XDR library routines
  27.      that are used for external data representation.  XDR routines allow
  28.      programmers to describe arbitrary data structures in a machine-
  29.      independent fashion.  Data for remote procedure calls (RPC) are
  30.      transmitted using XDR routines.  Class RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm enables one to decode
  31.      an XDR structure to a machine representation.  Class RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm
  32.      provides the capability to decode all the standard data types and vectors
  33.      of those data types.  An XDR stream must first be created by calling the
  34.      appropriate creation routine. XDR streams currently exist for
  35.      encoding/decoding of data to or from standard iostreams and file streams,
  36.      TCP/IP connections and Unix files, and memory. These creation routines
  37.      take arguments that are tailored to the specific properties of the
  38.      stream.  After the XDR stream has been created, it can then be used as
  39.      the argument to the constructor for a RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm object.  RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm
  40.      can be interrogated as to the status of the stream using member functions
  41.      bbbbaaaadddd(((()))), cccclllleeeeaaaarrrr(((()))), eeeeooooffff(((()))), ffffaaaaiiiillll(((()))), ggggoooooooodddd(((()))), and rrrrddddssssttttaaaatttteeee(((()))).
  42.  
  43. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  44.      None
  45.  
  46. EEEExxxxaaaammmmpppplllleeee
  47.      The example that follows is a "reader" program that decodes an XDR
  48.      structure from a file stream.  The example for class RRRRWWWWXXXXDDDDRRRRoooossssttttrrrreeeeaaaammmm is the
  49.      "writer" program that encodes the XDR structures onto the file stream.
  50.      The library that supports XDR routines must be linked in.  The name of
  51.      this library is not standard.
  52.  
  53.               #include <rw/xdrstrea.h>
  54.  
  55.  
  56.  
  57.               #include <rw/rstream.h>
  58.           #include <stdio.h>
  59.           main(){
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))                                          RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.            XDR xdr;
  75.            FILE* fp = fopen("test","r+");
  76.            xdrstdio_create(&xdr, fp, XDR_DECODE);
  77.  
  78.            RWXDRistream rw_xdr(&xdr);
  79.            int data;
  80.            for(int i=0; i<10; ++i) {
  81.              rw_xdr >> data;      // decode integer data
  82.              if(data == i)
  83.                cout << data << endl;
  84.              else
  85.                cout << "Bad input value" << endl;
  86.            }
  87.            fclose(fp);
  88.           }
  89.  
  90. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr
  91.               RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm(XDR* xp);
  92.  
  93.  
  94.      Initialize an RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm from the XDR structure xxxxpppp.
  95.  
  96.               RRRRWWWWXXXXDDDDrrrriiiissssttttrrrreeeeaaaammmm(streambuf*);
  97.  
  98.  
  99.      Initialize RWXDRistream with a pointer to streambuf. Streambuf must be
  100.      already allocated.
  101.  
  102.               RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm(istream&);
  103.  
  104.  
  105.      Initialize RWXDRistream with an input stream.
  106.  
  107. PPPPuuuubbbblllliiiicccc DDDDeeeessssttttrrrruuuuccccttttoooorrrr
  108.               ~virtual RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm();
  109.  
  110.  
  111.      Deallocate previously allocated resources.
  112.  
  113.  
  114.  
  115.  
  116.  
  117. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  118.               virtual int
  119.           ggggeeeetttt();
  120.  
  121.  
  122.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets and returns the next character from
  123.      the XDR input stream.  If the operation fails, it sets the failbit and
  124.      returns EEEEOOOOFFFF.
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))                                          RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.               virtual RWvistream&
  141.           ggggeeeetttt(char& c);
  142.  
  143.  
  144.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next character from the XDR
  145.      input stream and stores it in cccc. If the operation fails, it sets the
  146.      failbit. This member only preserves ASCII numerical codes, not the
  147.      coresponding character symbol.
  148.  
  149.               virtual RWvistream&
  150.           ggggeeeetttt(wchar_t& wc);
  151.  
  152.  
  153.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next wide character from the
  154.      XDR input stream and stores it in wwwwcccc. If the operation fails, it sets the
  155.      failbit.
  156.  
  157.               virtual RWvistream&
  158.           ggggeeeetttt(unsigned char& c);
  159.  
  160.  
  161.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next unsigned character from
  162.      the XDR input stream and stores it in cccc. If the operation fails, it sets
  163.      the failbit.
  164.  
  165.               virtual RWvistream&
  166.           ggggeeeetttt(char* v, size_t N);
  167.  
  168.  
  169.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets a vector of NNNN characters from the
  170.      XDR input stream and stores them in vvvv. If the operation fails, it sets
  171.      the failbit.
  172.  
  173.               virtual RWvistream&
  174.           ggggeeeetttt(unsigned char* v, size_t N);
  175.  
  176.  
  177.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets a vector of NNNN unsigned characters
  178.      from the XDR input stream and stores them in vvvv. If the operation fails,
  179.      it sets the failbit.
  180.  
  181.               virtual RWvistream&
  182.           ggggeeeetttt(double* v, size_t N);
  183.  
  184.  
  185.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets a vector of NNNN ddddoooouuuubbbblllleeees from the XDR
  186.      input stream and stores them in vvvv. If the operation fails, it sets the
  187.      failbit.
  188.  
  189.               virtual RWvistream&
  190.           ggggeeeetttt(float* v, size_t N);
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))                                          RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets a vector of NNNN ffffllllooooaaaatttts from the XDR
  207.      input stream and stores them in vvvv. If the operation fails, it sets the
  208.      failbit.
  209.  
  210.               virtual RWvistream&
  211.           ggggeeeetttt(int* v, size_t N);
  212.  
  213.  
  214.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets a vector of NNNN iiiinnnntttts from the XDR
  215.      input stream and stores them in vvvv. If the operation fails, it sets the
  216.      failbit.
  217.  
  218.               virtual RWvistream&
  219.           ggggeeeetttt(unsigned int* v, size_t N);
  220.  
  221.  
  222.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets a vector of NNNN unsigned iiiinnnntttts from
  223.      the XDR input stream and stores them in vvvv. If the operation fails, it
  224.      sets the failbit.
  225.  
  226.               virtual RWvistream&
  227.           ggggeeeetttt(long* v, size_t N);
  228.  
  229.  
  230.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets a vector of NNNN lllloooonnnnggggs from the XDR
  231.      input stream and stores them in vvvv. If the operation fails, it sets the
  232.      failbit.
  233.  
  234.               virtual RWvistream&
  235.           ggggeeeetttt(unsigned long* v, size_t N);
  236.  
  237.  
  238.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets a vector of NNNN unsigned lllloooonnnnggggs from
  239.      the XDR input stream and stores them in vvvv. If the operation fails, it
  240.      sets the failbit.
  241.  
  242.               virtual RWvistream&
  243.           ggggeeeetttt(short* v, size_t N);
  244.  
  245.  
  246.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets a vector of NNNN sssshhhhoooorrrrtttts from the XDR
  247.      input stream and stores them in vvvv. If the operation fails, it sets the
  248.      failbit.
  249.  
  250.               virtual RWvistream&
  251.           ggggeeeetttt(unsigned short* v, size_t N);
  252.  
  253.  
  254.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets a vector of NNNN unsigned sssshhhhoooorrrrtttts from
  255.      the XDR input stream and stores them in vvvv. If the operation fails, it
  256.      sets the failbit.
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))                                          RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.               virtual RWvistream&
  273.           ggggeeeetttt(wchar_t* v, size_t N);
  274.  
  275.  
  276.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets a vector of NNNN wide characters from
  277.      the XDR input stream and stores them in vvvv. If the operation fails, it
  278.      sets the failbit.
  279.  
  280.               virtual RWvistream&
  281.           ggggeeeettttSSSSttttrrrriiiinnnngggg(char* s, size_t maxlen);
  282.  
  283.  
  284.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Restores a character string from the XDR
  285.      input stream that was stored to the XDR output stream with
  286.      RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm::::::::ppppuuuuttttssssttttrrrriiiinnnngggg and stores the characters in the array starting
  287.      at ssss. The function stops reading at the end of the string or after
  288.      mmmmaaaaxxxxlllleeeennnn----1111 characters, whichever comes first.  If mmmmaaaaxxxxlllleeeennnn----1111 characters have
  289.      been read and the mmmmaaaaxxxxlllleeeennnnth character is not the string terminator, then
  290.      the failbit of the stream will be set.  In either case, the string will
  291.      be terminated with a null byte.
  292.  
  293.               virtual RWvistream&
  294.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(char& c );
  295.  
  296.  
  297.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next character from the XDR
  298.      input stream and stores it in cccc. If the operation fails, it sets the
  299.      failbit. This member attempts to preserve the symbolic characters' values
  300.      transmitted over the stream.
  301.  
  302.               virtual RWvistream&
  303.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(double& d);
  304.  
  305.  
  306.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next ddddoooouuuubbbblllleeee from the XDR input
  307.      stream and stores it in dddd. If the operation fails, it sets the failbit.
  308.  
  309.               virtual RWvistream&
  310.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(float& f);
  311.  
  312.  
  313.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next ffffllllooooaaaatttt from the XDR input
  314.      stream and stores it in ffff. If the operation fails, it sets the failbit.
  315.  
  316.               virtual RWvistream&
  317.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(int&  i);
  318.  
  319.  
  320.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next integer from the XDR input
  321.      stream and stores it in iiii. If the operation fails, it sets the failbit.
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))                                          RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))
  335.  
  336.  
  337.  
  338.               virtual RWvistream&
  339.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(long& l);
  340.  
  341.  
  342.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next lllloooonnnngggg from the XDR input
  343.      stream and stores it in llll. If the operation fails, it sets the failbit.
  344.  
  345.               virtual RWvistream&
  346.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(short& s);
  347.  
  348.  
  349.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next sssshhhhoooorrrrtttt from the XDR input
  350.      stream and stores it in ssss. If the operation fails, it sets the failbit.
  351.  
  352.               virtual RWvistream&
  353.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(wchar_t& wc);
  354.  
  355.  
  356.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next wide character from the
  357.      XDR input stream and stores it in wwwwcccc. If the operation fails, it sets the
  358.      failbit.
  359.  
  360.               virtual RWvistream&
  361.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(unsigned char& c);
  362.  
  363.  
  364.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next unsigned character from
  365.      the XDR input stream and stores it in cccc. If the operation fails, it sets
  366.      the failbit.
  367.  
  368.               virtual RWvistream&
  369.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(unsigned int& i);
  370.  
  371.  
  372.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next unsigned integer from the
  373.      XDR input stream and stores it in iiii. If the operation fails, it sets the
  374.      failbit.
  375.  
  376.               virtual RWvistream&
  377.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(unsigned long& l);
  378.  
  379.  
  380.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next unsigned lllloooonnnngggg from the XDR
  381.      input stream and stores it in llll. If the operation fails, it sets the
  382.      failbit.
  383.  
  384.               virtual RWvistream&
  385.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(unsigned short& s);
  386.  
  387.  
  388.      Redefined from class RRRRWWWWvvvviiiissssttttrrrreeeeaaaammmm. Gets the next unsigned sssshhhhoooorrrrtttt from the
  389.      XDR input stream and stores it in ssss. If the operation fails, it sets the
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))                                          RRRRWWWWXXXXDDDDRRRRiiiissssttttrrrreeeeaaaammmm((((3333CCCC++++++++))))
  401.  
  402.  
  403.  
  404.      failbit.
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.